public class Problem24 {
	public static void main (String[] args) {
		long nth = 1000000L;
		int n = 10;	// 0 - 9

		int[] numbers = new int[n];
		for (int i = 0; i < n; ++i)
			numbers[i] = i;

		int[] res = new int[n];
		
		for (int i = 0; i < n; ++i) {
			long temp = factorial(n-1-i);
			long index = (nth-1)/temp;
			int j = 0;
			while(true) {
				if (numbers[j] == -1) {
					++j;
					continue;
				}

				if (index == 0)
					break;
				index--;
				j++;
			}

			res[i] = j;
			numbers[j] = -1;
			nth = (nth-1)%temp + 1;
		}

		for (int r : res)
			System.out.print("" + r);
		System.out.println();
	}

	private static long factorial(int n) {
		long res = 1L;
		for (int i = 2; i <= n; ++i)
			res *= i;

		return res;
	}
}
